package bmaso.purest;

import java.util.ArrayList;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

import bmaso.purest.operation.ServiceOperation;

/**
 * An instance of this tag can create and invoke a ServiceOperation
 * instance, passing up to 20 Object input values to the
 * operation.
 */
public class ServiceOperationTag extends TagSupport {
	private PageContext pc;
	private Class<?> clazz;
	
	@Override
	public int doEndTag() throws JspException {
		ServiceOperation so = null;
		try {
			so = (ServiceOperation)clazz.newInstance();
		} catch(IllegalAccessException iae) {
			throw new RuntimeException(iae);
		} catch(InstantiationException ie) {
			throw new RuntimeException(ie);
		}
		
		so.invoke(pc, param1, param2, param3, param4, param5,
				param6, param7, param8, param9, param10,
				param11, param12, param13, param14, param15,
				param16, param17, param18, param19, param20);
		
		return SKIP_BODY;
	}
	
	@Override
	public void setPageContext(PageContext pageContext) {
		super.setPageContext(pageContext);
		this.pc = pageContext;
	}
	
	public String getOpClass() {
		return clazz != null ? clazz.getName() : "";
	}
	
	public void setOpClass(String opClass) {
		try {
			clazz = Class.forName(opClass);
			if(!ServiceOperation.class.isAssignableFrom(clazz)) {
				Class<?> temp = clazz;
				clazz = null;
				throw new IllegalArgumentException(temp.getName() + " does not implement " +
						ServiceOperation.class.getName());
			}
		} catch(ClassNotFoundException cnfe) {
			throw new IllegalArgumentException(cnfe);
		}
	}
	
	private Object param1;
	private Object param2;
	private Object param3;
	private Object param4;
	private Object param5;
	private Object param6;
	private Object param7;
	private Object param8;
	private Object param9;
	private Object param10;
	private Object param11;
	private Object param12;
	private Object param13;
	private Object param14;
	private Object param15;
	private Object param16;
	private Object param17;
	private Object param18;
	private Object param19;
	private Object param20;

	public Object getParam1() {
		return param1;
	}

	public void setParam1(Object param1) {
		this.param1 = param1;
	}

	public Object getParam2() {
		return param2;
	}

	public void setParam2(Object param2) {
		this.param2 = param2;
	}

	public Object getParam3() {
		return param3;
	}

	public void setParam3(Object param3) {
		this.param3 = param3;
	}

	public Object getParam4() {
		return param4;
	}

	public void setParam4(Object param4) {
		this.param4 = param4;
	}

	public Object getParam5() {
		return param5;
	}

	public void setParam5(Object param5) {
		this.param5 = param5;
	}

	public Object getParam6() {
		return param6;
	}

	public void setParam6(Object param6) {
		this.param6 = param6;
	}

	public Object getParam7() {
		return param7;
	}

	public void setParam7(Object param7) {
		this.param7 = param7;
	}

	public Object getParam8() {
		return param8;
	}

	public void setParam8(Object param8) {
		this.param8 = param8;
	}

	public Object getParam9() {
		return param9;
	}

	public void setParam9(Object param9) {
		this.param9 = param9;
	}

	public Object getParam10() {
		return param10;
	}

	public void setParam10(Object param10) {
		this.param10 = param10;
	}

	public Object getParam11() {
		return param11;
	}

	public void setParam11(Object param11) {
		this.param11 = param11;
	}

	public Object getParam12() {
		return param12;
	}

	public void setParam12(Object param12) {
		this.param12 = param12;
	}

	public Object getParam13() {
		return param13;
	}

	public void setParam13(Object param13) {
		this.param13 = param13;
	}

	public Object getParam14() {
		return param14;
	}

	public void setParam14(Object param14) {
		this.param14 = param14;
	}

	public Object getParam15() {
		return param15;
	}

	public void setParam15(Object param15) {
		this.param15 = param15;
	}

	public Object getParam16() {
		return param16;
	}

	public void setParam16(Object param16) {
		this.param16 = param16;
	}

	public Object getParam17() {
		return param17;
	}

	public void setParam17(Object param17) {
		this.param17 = param17;
	}

	public Object getParam18() {
		return param18;
	}

	public void setParam18(Object param18) {
		this.param18 = param18;
	}

	public Object getParam19() {
		return param19;
	}

	public void setParam19(Object param19) {
		this.param19 = param19;
	}

	public Object getParam20() {
		return param20;
	}

	public void setParam20(Object param20) {
		this.param20 = param20;
	}
	

}
